using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLDAL;
using System.Data.SqlClient;

/// <summary>
/// Summary description for FoodBll
/// </summary>
public class FoodBll
{
	public FoodBll()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    #region List all Food
    public SqlDataReader ListAllFood()
    {        
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Food_ListAll", null);
    }
    #endregion

    #region List Food by Restaurant
    public SqlDataReader ListFoodByRestaurant(RestaurantInfo resInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@resID", SqlDbType.VarChar, 10)
            };
        cmdParms[0].Value = resInfo.ResID;

        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
           CommandType.StoredProcedure, "sp_Food_ListFoodByRestaurant", null);
    }
    #endregion

    #region List Food by Type
    public SqlDataReader ListFoodByRestaurant(FoodInfo foodInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@typeID", SqlDbType.Int)
            };
        cmdParms[0].Value = foodInfo.TypeID;

        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
           CommandType.StoredProcedure, "sp_Food_ListFoodByType", null);
    }
    #endregion

    #region Create new Food
    public int CreateFood(FoodInfo foodInfo)
    {
        SqlParameter[] cmdParms = {
            new SqlParameter("@foodID", SqlDbType.VarChar, 10),
            new SqlParameter("@foodName", SqlDbType.VarChar, 100),
            new SqlParameter("@typeID", SqlDbType.Int),
            new SqlParameter("@numberOfPerson", SqlDbType.Int),
            new SqlParameter("@price", SqlDbType.Float),
            new SqlParameter("@foodPicture", SqlDbType.VarChar, 200),
            new SqlParameter("@foodDescription", SqlDbType.VarChar, 1000)
        };

        cmdParms[0].Value = foodInfo.FoodID;
        cmdParms[1].Value = foodInfo.FoodName;
        cmdParms[2].Value = foodInfo.TypeID;
        cmdParms[3].Value = foodInfo.NumberOfPerson;
        cmdParms[4].Value = foodInfo.Price;
        cmdParms[5].Value = foodInfo.FoodPicture;
        cmdParms[6].Value = foodInfo.FoodDescription;
        
        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Food_Create", cmdParms);

        return result;

    }
    #endregion

    #region Update Food's Information
    public int UpdateFood(FoodInfo foodInfo)
    {
        SqlParameter[] cmdParms = {
            new SqlParameter("@foodID", SqlDbType.VarChar, 10),
            new SqlParameter("@foodName", SqlDbType.VarChar, 100),
            new SqlParameter("@typeID", SqlDbType.Int),
            new SqlParameter("@numberOfPerson", SqlDbType.Int),
            new SqlParameter("@price", SqlDbType.Float),
            new SqlParameter("@foodPicture", SqlDbType.VarChar, 200),
            new SqlParameter("@foodDescription", SqlDbType.VarChar, 1000)
        };

        cmdParms[0].Value = foodInfo.FoodID;
        cmdParms[1].Value = foodInfo.FoodName;
        cmdParms[2].Value = foodInfo.TypeID;
        cmdParms[3].Value = foodInfo.NumberOfPerson;
        cmdParms[4].Value = foodInfo.Price;
        cmdParms[5].Value = foodInfo.FoodPicture;
        cmdParms[6].Value = foodInfo.FoodDescription;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Food_Update", cmdParms);

        return result;
    }
    #endregion

    #region Delete Food
    public int DeleteFood(FoodInfo foodInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@foodID", SqlDbType.VarChar, 10)
            };
        cmdParms[0].Value = foodInfo.FoodID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Food_Delete", cmdParms);
        return result;
    }
    #endregion

    #region List Details Food   

    public SqlDataReader ListDetailsFood(FoodInfo foodInfo)
    {
        SqlParameter[] parms = { 
                new SqlParameter("@foodID", SqlDbType.VarChar, 10)};
        parms[0].Value = foodInfo.FoodID;

        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, 
            CommandType.StoredProcedure, "sp_Food_ListDetailsFood", parms);
    }
    #endregion


    /// <summary>
    /// By Phuong
    /// Date: 7/5/2008
    /// </summary>
    /// <returns></returns>
    /// 
    #region List 4 special Foods
    public SqlDataReader List4Food()
    {
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Food_List4Food", null);
    }
    #endregion

    /// <summary>
    /// By: PHUONG
    /// Date: 8/5/2009
    /// </summary>
    /// <param name="dropDownList"></param>
    /// 
    #region Load food to dropdownlist when select a type 
    public void LoadFoodByType(DropDownList dropDownList, TypeOfFoodInfo typeFoodInfo)
    {
        SqlParameter[] parms = { 
            new SqlParameter("@typeID", SqlDbType.Int, 4)
        };
        parms[0].Value = typeFoodInfo.TypeID;
        DataSet ds = SQLHelper.GetDataSetUsingSP(CommandType.StoredProcedure, "sp_Food_ListFoodByType", "Food", parms);
        dropDownList.DataSource = ds.Tables["Food"];
        dropDownList.DataTextField = "foodName";
        dropDownList.DataValueField = "foodID";
        dropDownList.DataBind();
        dropDownList.Items.Insert(0, "--Select food--");

    }
    #endregion

    #region Search food by food name

    public void ListFoodByFoodName(FoodInfo foodInfo, DataList dataList )
    {
        SqlParameter[] parms = {
            new SqlParameter("@foodName", SqlDbType.VarChar, 10)};
        parms[0].Value = foodInfo.FoodName;
        DataSet ds = SQLHelper.GetDataSetUsingSP(CommandType.StoredProcedure, "sp_Food_SearchFoodByFoodName", "Food", parms);
        dataList.DataSource = ds.Tables["Food"];
        dataList.DataBind();
    }
    #endregion
}
